<?php
    include 'connectSQL.php';
	class NhanVien
	{
		var $manv;
		var $tennv;
		var $matkhau;
		var $nhom;
        function __construct($nmanv,$ntennv,$nmatkhau,$nnhom){
            $this->manv = $nmanv;
            $this->matkhau = $nmatkhau;
            $this->tennv= $ntennv;
            $this->nhom = $nnhom;    
            connectSQL();  
        }
    
		function ThemNhanVien()	
		{
           $query = "INSERT INTO qlscmt.nhanvien (id ,manv ,tennv ,matkhau ,nhom
                    ) VALUES (NULL,'$this->manv','$this->tennv', '$this->matkhau','$this->nhom')";
           echo $query;
            if(mysql_query($query))
               echo "Them";
             else
                echo mysql_error();
		}
        function XoaNhanVien($nma)
        {
            $query = "DELETE 
                        FROM qlscmt.nhanvien
                        WHERE id = $nma";
            echo $query;
            if(mysql_query($query))
               echo "Xoa";
             else
                echo mysql_error();
        }
        function SuaNhanVien($id,$nmanv,$ntennv,$nmatkhau,$nnhom)
        {
            $this->manv = $nmanv;
            $this->matkhau = $nmatkhau;
            $this->tennv= $ntennv;
            $this->nhom = $nnhom; 
            $query = "UPDATE qlscmt.nhanvien
                        SET manv='$nmanv', tennv='$ntennv', matkhau='$nmatkhau',nhom='$nnhom'
                        WHERE id = $id";
            if(mysql_query($query))
               echo "Sua";
             else
                echo mysql_error();
        }
        function DangNhap($nmanv,$nmatkhau)
        {
            $query = "Select * from nhanvien where manv = '$nmanv' and matkhau = '$nmatkhau'";
            $result = mysql_query($query);
            $count=mysql_num_rows($result);
            if($count==1){
                while ($row = mysql_fetch_object($result)) {
                    $this->manv = $row->manv;
                    $this->matkhau = $row->matkhau;
                    $this->tennv= $row->tennv;
                    $this->nhom = $row->nhom;   
                    echo "Login";
                    return true;
                }
            }
            else
            {   
                echo "Login False";
                return false;
            }
        }
	}
?>